From 03adcb9bff8cb4a2ffcb442f6e8f787ea205feb4 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 19 Dec 2022 17:13:41 +0700 Subject: loading not stop when cart is empty, fix input quantity --- src/pages/shop/product/[slug].js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/pages/shop/product/[slug].js') diff --git a/src/pages/shop/product/[slug].js b/src/pages/shop/product/[slug].js index b8d29d02..7ce55562 100644 --- a/src/pages/shop/product/[slug].js +++ b/src/pages/shop/product/[slug].js @@ -77,12 +77,18 @@ export default function ProductDetail({ product }) { } }, [selectedVariant, product]); - let onchangeVariant = (e) => { + const onchangeVariant = (e) => { setSelectedVariant(e.target.value); - setQuantity("1"); } - let addItemToCart = () => { + const onChangeQuantity = (e) => { + let inputValue = e.target.value; + inputValue = parseInt(inputValue); + inputValue = Math.floor(inputValue); + setQuantity(inputValue); + } + + const addItemToCart = () => { if (product.variant_total > 1 && !selectedVariant) { toast.error('Pilih varian terlebih dahulu untuk menambahkan ke keranjang', { duration: 2000 }); return false; @@ -148,7 +154,7 @@ export default function ProductDetail({ product }) {
- setQuantity(e.target.value)} /> +
-- cgit v1.2.3